# -*- coding: utf-8 -*-

from flask import Flask, request, jsonify
from flasgger import Swagger
from flask_cors import *
from config import Config
from datetime import timedelta
from src.BM25_ import BM25

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
app.config['JSONIFY_MIMETYPE'] = "application/json;charset=utf-8"
app.secret_key = Config.APP_SECRET_KEY
app.permanent_session_lifetime = timedelta(days=1)
app.session_cookie_name = Config.APP_SESSION_COOKIE_NAME
CORS(app, suppors_credentials=True, resources={r'/*'})  # 设置跨域
swagger = Swagger(app)
BM25 = BM25()


@app.route(Config.API_INDEX + 'BM25API', methods=['GET'])
def BM25API():
    """
    BM25检索
    :return:
    """
    return jsonify({"status": 200, "msg": "ok", "result": BM25.predict(request.args.get('word', ""))})


if __name__ == '__main__':
    app.run('0.0.0.0', port=Config.PYTHON_PORT)
